import { reactive } from "vue";

const Chart = reactive({
  curNow: 0,
  tablist: [
    {
      title: "日",
      value: 1,
    },
    {
      title: "月",
      value: 2,
    },
    {
      title: "年",
      value: 3,
    },
  ],
  chartData: {},
  opts: {
    color: ["#fbb64d"],
    padding: [15, 15, 0, 5],
    enableScroll: false,
    legend: { show: false },
    xAxis: {
      disableGrid: true,
    },
    yAxis: {
      data: [
        {
          min: 0,
        },
      ],
    },
    extra: {
      column: {
        type: "group",
        width: 20,
        activeBgColor: "#000000",
        activeBgOpacity: 0.08,
      },
    },
  },
});

const getChartData = (data: any) => {
  //模拟从服务器获取数据时的延时
  setTimeout(() => {
    //模拟服务器返回数据，如果数据格式和标准格式不同，需自行按下面的格式拼接
    let res = {
      categories: [
        "2018",
        "2019",
        "2020",
        "2021",
        "2022",
        "2023",
        "2018",
        "2019",
        "2020",
        "2021",
        "2022",
        "2023",
        "2018",
        "2019",
        "2020",
        "2021",
        "2022",
        "2023",
      ],
      series: [
        {
          name: "总收入（万元）",
          data: [35, 36, 31, 33, 13, 34, 35, 36, 31, 33, 13, 34, 35, 36, 31, 33, 13, 34],
        },
      ],
    };
    Chart.chartData = JSON.parse(JSON.stringify(res));
  }, 500);
};

export default {
  Chart,
  getChartData,
};
